﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;
using System.Reflection;
using NewsClassifierFreshnessMeasurement.Model;
using AutoExtractQueryToXMLFile;

namespace ProduceExtractionXMLFile
{
    class Program
    {
        static void Main(string[] args)
        {
             //Console.Write(Guid.NewGuid());
             List<InputPackage> listInputPkg = new List<InputPackage>();
             string connStringToDownloadNews = "server=lsstc259;database=NewsClassifierFreshMeasurement;uid =freshnessReader;pwd=@freshnessReader@";
            
             string sqlCmd = "";
             Console.WriteLine("Sql Command:");
             sqlCmd = Console.ReadLine();
             //sqlCmd = "select * from newsitemlist where ID in ('346717','346687','346662','346647','346631','346583','346560','346501','346493','346339')";
             //Console.WriteLine("Download News...");
             //List<News> listNews = pro.GetNewsFromDatabase(connStringToDownloadNews,sqlCmd);
             //Console.WriteLine("News Count = {0}", listNews.Count);

             do
             {
                 InputPackage pkg = new InputPackage();
                 Console.WriteLine("\n\n\nFactory dll file path:(input 'end' to end configuration input)");
                 string dllFilePath = Console.ReadLine();
                 if (dllFilePath == "end")
                     break;
                 
                 //Type[] types = pro.GetAllTypeName(dllFilePath);
                 //foreach (Type t in types)
                 //{
                 //    Console.WriteLine(t.FullName);
                 //}

                 Console.WriteLine("\nFactory class type:");
                 string tmpTypeName = Console.ReadLine();

                 pkg.FactoryDLLFileName = dllFilePath;
                 pkg.ClassTypeName = tmpTypeName;

                 List<Stream> listConfigStream = new List<Stream>();
                 List<string> listAppendix = new List<string>();
                 do
                 {
                     Console.WriteLine("\nConfiguration file path (input 'end' to end configuration input):");
                     string tmpConfigPath = Console.ReadLine();
                     if (tmpConfigPath == "end")
                         break;
                     listConfigStream.Add(File.OpenRead(tmpConfigPath));
                     Console.WriteLine("\nAppendix:");
                     string tmpAppendix = Console.ReadLine();
                     listAppendix.Add(tmpAppendix);


                 } while (true);
                 pkg.ListConfigStream = listConfigStream;
                 pkg.ListAppendix = listAppendix;
                 
                 //InputPkg inputPkg = new InputPkg()
                 //{
                 //    _listNews = listNews,
                 //    _dllFilePath = dllFilePath,
                 //    _tmpTypeName = tmpTypeName,
                 //    _listConfigPath = listConfigPath,
                 //    _listAppendix = listAppendix
                 //};
                 listInputPkg.Add(pkg);


             } while (true);

             Console.WriteLine("\nOutput xml filepath:");
             string tmpOuputPath = Console.ReadLine();
             Console.WriteLine("Produce file ...");

             ProduceAllFile pro = new ProduceAllFile(connStringToDownloadNews, sqlCmd,tmpOuputPath);
             pro.CreateFile(listInputPkg);
        }
    }
}
